board = [' ', ' ', ' ' ,' ' ,' ', ' ', ' ', ' ' ,' ']



def updateBoard(board):
    print(board[0], '|', board[1], '|', board[2])
    print('__|___|__')
    print('  |   |  ')
    print(board[3], '|', board[4], '|', board[5])
    print('__|___|__')
    print('  |   |  ')
    print(board[6], '|', board[7], '|', board[8])

updateBoard(board)
pcount = 1
win = 0
print('Player 1 is X and Player 2 is O')
for n in range(0, 9):
    
    if (pcount == 1):
        p = "Player 1"
        
    elif(pcount == 2):
        p = "Player 2"
        
    move1 = int(input(p +" please make first move\n"))
    move1 = move1-1
    if(pcount == 1):
        board[move1]='O'
        pcount = 2
        
    else:
        board[move1] = 'X'
        pcount = 1
        
        
    updateBoard(board)

    #possibilities 0-1-2, 3-4-5, 6-7-8, 0-3-6, 1-4-7, 2-5-8, 0-4-8, 2-4-6

    if (board[0]== board[1] == board[2]):
        if(board[0] == 'X'):
            win = 2
            break
        elif(board[0]=='O'):
            win=1
            break
        else:
            b=1
    elif (board[3]== board[4] == board[5]):
        if(board[3] == 'X'):
            win = 2
            break
        elif(board[3]=='O'):
            win=1
            break
        else:
            b=1

    elif (board[6]== board[7] == board[8]):
        if(board[6] == 'X'):
            win = 2
            break
        elif(board[6]=='O'):
            win=1
            break
        else:
            b=1

    elif (board[0]== board[3] == board[6]):
        if(board[0] == 'X'):
            win = 2
            break
        elif(board[0]=='O'):
            win=1
            break
        else:
            b=1

    elif (board[1]== board[4] == board[7]):
        if(board[1] == 'X'):
            win = 2
            break
        elif(board[1]=='O'):
            win=1
            break
        else:
            b=1

    elif (board[2]== board[5] == board[8]):
        if(board[2] == 'X'):
            win = 2
            break
        elif(board[2]=='O'):
            win=1
            break
        else:
            b=1

    elif (board[0]== board[4] == board[8]):
        if(board[0] == 'X'):
            win = 2
            break
        elif(board[0]=='O'):
            win=1
            break
        else:
            b=1
    elif (board[2]== board[4] == board[6]):
        if(board[0] == 'X'):
            win = 2
            break
        elif(board[0]=='O'):
            win=1
            break
        else:
            b=1


if(win==2):
    print('player 2 wins')

elif(win==1):
    print('player 1 wins')
            
    
                                                                                                                                                                                                                                                                                                           




















    
    
    

